<template>
  <div class="yy-gd-Integrated-query">
    <!--列表-->
    <div class="yy-gd-Integrated-query-list" v-show="type=='list'">
      <Card>
        <p slot="title">
          <Icon type="md-list" />
          工单综合查询
        </p>
        <Form ref="formSearch" :model="formSearch"  inline>
            <FormItem prop="user">
              <Select class="select" v-model="formSearch.cateName"  placeholder="请选择工单状态">
                <Option value="">全部</Option>
              </Select>
            </FormItem>
            <FormItem prop="user">
              <Select class="select" v-model="formSearch.cateName"  placeholder="请选择工单状态">
                <Option value="">全部</Option>
              </Select>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSearch()">查询</Button>
            </FormItem>
        </Form>
        <Table :columns="columns" :data="data" ></Table>
        <div style="margin: 10px;overflow: hidden">
          <div style="float: right;">
              <Page :total="page.total" :page-size="page.pageSize" :current="1" @on-change="changePage" show-total></Page>
          </div>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import API from "./api";
import ValidatorRule from "@/filters/validator-rule";
import { formatNetTime } from "@/libs/tools";
import i18n from "./locale";

export default {
  name: "yy-gd-Integrated-query",
  data() {
    return {
      i18n: i18n,
      currentData: "",
      detailsModal: false,
      type: "list",
      page: {
        total: 0,
        pageSize: 20
      },
      formSearch: {
        cateNum: "",
        cateName: "",
        userID: "",
        userName: "",
        b_UserRole: ""
      },
      editFormInLine: {
        cateNum: "",
        cateName: "",
        cateRemark: "",
        userID: "chenweihan",
        userName: "陈维汉",
        b_UserRole: "admin"
      },
      editFormRuleInline: {
        cateNum: ValidatorRule.require,
        cateName: ValidatorRule.require
      },
      columns: [
        {
          title: "工单号",
          key: "gdCode"
        },
        {
          title: "工单状态",
          key: "gdZht"
        },
        {
          title: "任务级别 ",
          key: "createUser"
        },
        {
          title: "维修班组 ",
          key: "wxKeshi"
        },
        {
          title: "维修事项 ",
          key: "wxXm"
        },
        {
          title: "报修科室 ",
          key: "bxKeshi"
        },
        {
          title: "报修时间 ",
          key: "gdShij"
        },
        {
          title: "故障位置 ",
          key: "wxDidian"
        },
        {
          title: "故障描述 ",
          key: "bxBeizhu"
        },
        {
          title: "维修备注 ",
          key: "wxBeizhu"
        },
        {
          title: "报修人 ",
          key: "bxRen"
        },
        {
          title: "关单人 ",
          key: "pjRen"
        },
        {
          title: "维修人 ",
          key: "wxUserNames"
        },
        {
          title: "评价 ",
          key: "cateRemark"
        },
        {
          title: "完工时间 ",
          key: "wanGongShij"
        }
      ],
      data: []
    };
  },

  mounted() {
    this.userInfo = this.$store.state.user.userInfo;
    this.handleSearch();
  },

  computed: {},

  methods: {
    handleSearch() {
      let obj = this.formSearch;
      obj.pageNum = 1;
      obj.pageSize = this.page.pageSize;
      this.formSearch = obj;
      this.getList(obj);
    },

    getList(obj) {
      API.getList(obj)
        .then(res => {
          if (res.code == 200) {
            let data = res.data;
            if (data != null) {
              this.page.total = data.total;
              this.page.pageSize = data.pageSize;
              this.data = data.list;
            } else {
              this.$Message.success({ content: "暂无数据！" });
              this.data = [];
            }
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
    },

    changePage(pageNum) {
      let obj = this.formSearch,
        maxPageNum = Math.ceil(this.page.total / this.page.pageSize);
      if (obj.pageNum > maxPageNum) {
        obj.pageNum = maxPageNum;
      } else {
        obj.pageNum = pageNum;
      }
      this.formSearch = obj;
      this.getList(obj);
    },

    goBack() {
      this.type = "list";
    },

    resetList() {
      //求余为1，页码为最大页码，请求页需减1
      let maxPageNum = Math.ceil(this.page.total / this.page.pageSize);
      let remainderNum = this.page.total % this.page.pageSize;
      if (
        this.formSearch.pageNum == maxPageNum &&
        remainderNum == 1 &&
        this.formSearch.pageNum !== 1
      ) {
        this.formSearch.pageNum = this.formSearch.pageNum - 1;
      }
      let obj = this.formSearch;
      this.getList(obj);
    },

    handleReset() {
      this.$refs.editForm.resetFields();

      if (this.type == "edit") {
        this.editFormInLine.itemNum = this.currentData.itemNum;
        this.editFormInLine.itemName = this.currentData.itemName;
        this.editFormInLine.cateNum = this.currentData.cateNum;
      }
    },

    editSubmit(obj) {
      this.formSearch.cateNum = obj.cateNum;
      obj.userID = this.userInfo.userId;
      //obj.id = this.currentData.id;
      API.editSubmit(obj)
        .then(res => {
          if (res.code == 200) {
            this.resetList();
            this.$Message.success("修改成功！");
            this.goBack();
          }
        })
        .catch(err => {
          this.$Message.error("修改异常！");
        });
    },

    addSubmit(obj) {
      obj.userID = this.userInfo.userId;
      API.addSubmit(obj)
        .then(res => {
          if (res.code == 200) {
            this.handleSearch();
            this.$Message.success("添加成功！");
            this.goBack();
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
    }
  }
};
</script>
<style lang="less" >
@import "./yy-gd-Integrated-query.less";
</style>
